package com.zhiwang.planet.mvp.p

import android.annotation.SuppressLint
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.model.entity.main.Banner
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseFunc
import javax.inject.Inject


@ActivityScope
class ActivityPresenter @Inject constructor(var restApi: RestApi, var scopeProvider: AndroidLifecycleScopeProvider) {


    @SuppressLint("CheckResult")
    fun loadBanner(onSuccess: (List<Banner>) -> Unit, onError: (Throwable) -> Unit) {

        restApi.getIndexActivities()
                .responseFunc()
                .map { it.bottomActivities }
                .map { it.map { Banner(it.img,it.url) } }
                .androidSchedule()
                .subscribe({
                    onSuccess.invoke(it)
                }, {

                }, {

                })


    }
}